import java.io.*;
import java.util.*;


public class ParkitUser implements Serializable{
	private String name;
	private Vector<Spot> spots;
	private float lat;
	private float lng;
	
	public ParkitUser()
	{
		spots = new Vector<Spot> ();
	}
	
	public ParkitUser(float l1, float l2)
	{
		lat = l1;
		lng = l2;
		spots = new Vector<Spot> ();
	}
	
	public void initSpots(ParkitDriver d)
	{
		for(Spot p: d.getSpots())
		{
			if ((p.getLat() == lat) && (p.getLng() ==lng))
				spots.add(p);
		}
	}
	
	public float getLat()
	{
		return lat;
	}
	
	public float getLng()
	{
		return lng;
	}
	
	public Spot getOpenSpot()
	{
		if(spots.isEmpty())
			return null;
		return spots.get(0);
	}
	
	public Spot getOpenSpot(int p)
	{
		
		for(Spot s: spots)
		{
			if (s.equals(spots.get(p)))
			{
				s.setOpen(false);
			}
			if(s.isOpen())
			{
				return s;
			}
		}
		return null;
	}
	
	public void addSpot(Spot s)
	{
		spots.add(s);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ParkitUser other = (ParkitUser) obj;
		if (Float.floatToIntBits(lat) != Float.floatToIntBits(other.lat))
			return false;
		if (Float.floatToIntBits(lng) != Float.floatToIntBits(other.lng))
			return false;
		return true;
	}
	
}
